package com.calvin.study.mapper.xml;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.calvin.study.model.sys.SysUser;

@Repository
public interface SysUserMapper extends BaseMapper<SysUser> {
	
	@Select("\r\n" + 
			"SELECT \r\n" + 
			"  role_code	\r\n" + 
			"FROM\r\n" + 
			"  sys_role r \r\n" + 
			"  LEFT JOIN sys_user_role ur \r\n" + 
			"    ON r.role_id = ur.role_id \r\n" + 
			"  LEFT JOIN sys_user u \r\n" + 
			"    ON u.user_id = ur.user_id \r\n" + 
			"WHERE u.user_name = #{userName}")
	List<String> findRoleByUserName(@Param("userName") String userName);
	
	@Select({"<script>",
				"SELECT", 
				  "DISTINCT url",
				"FROM",
				  "sys_menu m", 
				 " LEFT JOIN sys_role_menu rm", 
				    "ON m.`menu_id` = rm.`menu_id`", 
				 " LEFT JOIN sys_role r", 
				   " ON r.`role_id` = rm.`role_id`", 
				"WHERE r.`role_code` IN",
				"<foreach collection='roleCodes' item='roleCode' open='(' separator=',' close=')'>",
				  	"#{roleCode}",
				"</foreach>",
			 "</script>"})
	List<String> findAuthByRoleCodes(@Param("roleCodes") List<String> roleCodes);
}
